package tt.dz.order.service.rpc.rpchander;

import java.util.List;

import org.apache.avro.generic.GenericRecord;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSONException;

import tt.dz.order.exception.BusinessException;
import tt.dz.order.service.OrderService;
import tt.dz.order.util.OrderConstant.BizSystemCode;
import tt.dz.order.vo.RetVO;
import tt.dz.order.vo.ThdPayWayRecord;

@Component("queryThdPayWayRecordbyOrderNoHander")
public class QueryThdPayWayRecordbyOrderNoHander implements BaseHander {
	private static Logger log = LoggerFactory.getLogger(QueryThdPayWayRecordbyOrderNoHander.class);
	@Autowired
	OrderService orderService;
	private String paramName = "request";

	@Override
	public RetVO dohander(GenericRecord req) {
		RetVO retVO = new RetVO(RetVO.SuccessCode, null, null);
		// 订单号查询第三方支付信息
		try {
			String reqStr = req.get(paramName).toString();
			log.info("订单号查询第三方支付信息reqStr：" + reqStr);
			List<ThdPayWayRecord> thdPayWayRecordVos = orderService.queryThdPayWayRecordbyOrderNo(reqStr);
			retVO.setBizData(thdPayWayRecordVos);
		} catch (JSONException e) {
			log.error("订单号查询第三方支付信息发生异常", e);
			retVO.setRetCode(RetVO.FailCode);
			retVO.setResultCode(new StringBuilder(BizSystemCode.OrderServer.value())
					.append(new BusinessException("").getExceptionCode()).append("00").toString());
			retVO.setErrorMsg(e.getMessage());
		} catch (BusinessException e) {
			log.error("订单号查询第三方支付信息发生异常", e);
			retVO.setRetCode(RetVO.FailCode);
			retVO.setResultCode(e.getExceptionCode());
			retVO.setErrorMsg(e.getMessage());
		} catch (Exception e) {
			log.error("订单号查询第三方支付信息发生异常", e);
			retVO.setRetCode(RetVO.FailCode);
			retVO.setResultCode("1020300");
			retVO.setErrorMsg(e.getMessage());
		}
		return retVO;
	}

}
